package com.fizzkai.p2p.bussness.service.impl;

import com.fizzkai.p2p.bussness.domain.Bid;
import com.fizzkai.p2p.bussness.mapper.BidMapper;
import com.fizzkai.p2p.bussness.service.IBidService;
import com.fizzkai.p2p.core.query.QueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service@Transactional
public class BidServiceImpl implements IBidService {

    @Autowired
    private BidMapper bidMapper;

    @Override
    public int save(Bid entity) {
        return bidMapper.insert(entity);
    }

    @Override
    public int update(Bid entity) {
        return bidMapper.updateByPrimaryKey(entity);
    }

    @Override
    public Bid get(Long id) {
        return bidMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Bid> query(QueryObject qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        List<Bid> list = bidMapper.queryList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void updateState(Long bidRequestId, int state) {
        bidMapper.updateState(bidRequestId, state);
    }
}
